package com.huiyi.pan.server;

import com.huiyi.pan.core.constants.HPanConstants;
import com.huiyi.pan.core.response.R;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.NotBlank;

@SpringBootApplication(scanBasePackages = HPanConstants.BASE_COMPONENT_SCAN_PATH)
@ServletComponentScan(basePackages = {HPanConstants.BASE_COMPONENT_SCAN_PATH})
@RestController
@Slf4j
@Validated
@EnableTransactionManagement
@MapperScan(basePackages = HPanConstants.BASE_COMPONENT_SCAN_PATH + ".server.modules.**.mapper")
@Api("测试接口类")
@EnableAsync
public class HPanServerLauncher {

    public static void main(String[] args) {
        SpringApplication.run(HPanServerLauncher.class);
    }

    // 测试使用
    @GetMapping("/hello")
    public R<String> hello(@NotBlank(message = "name不能为空") String name, @NotBlank(message = "name2不能为空") String name2){
        // 打印类加载器
        /**
         * TomcatEmbeddedWebappClassLoader 主加载器
         *   context: ROOT
         *   delegate: true
         * ----------> Parent Classloader:
         * sun.misc.Launcher$AppClassLoader@18b4aac2 父加载器用你了appclassloader
         *
         * 设置热部署类后，加载器更换成 spring 的 RestartClassLoader
         * <dependency>
         *   <groupId>org.springframework.boot</groupId>
         *   <artifactId>spring-boot-devtools</artifactId>
         *   <optional>true</optional>
         *   <scope>provided</scope>
         * </dependency>
         *
         * TomcatEmbeddedWebappClassLoader
         *   context: ROOT
         *   delegate: true
         * ----------> Parent Classloader:
         * org.springframework.boot.devtools.restart.classloader.RestartClassLoader@7248d5f8
         *
         * 还需要在setting里设置
         * advance settings ->
         * Allow auto-make to start even if developed application is currently running
         *
         * compile ->
         * build project automatically
         */
        System.out.println( Thread.currentThread().getContextClassLoader() );
        return R.success("hello " + name + "！！ have changed");
    }

}
